//////////////////////////////////////////////////////////////////////
//
//	Copyright 2010-2011 Rogo's Team. All Rights Reserved
//
//////////////////////////////////////////////////////////////////////
package com.rogo.mvc.sub.observer
{
	import com.rogo.mvc.interfaces.INotification;
	import com.rogo.mvc.interfaces.IObserver;
	
	/**
	 * 观察者
	 * 
	 * <p>用来接收通知，观察者的属性有<br>
	 * <code>notifyFun</code> 派发的任务<br>
	 * <code>notifyCon</code> 派发人</p>
	 * 
	 * @author coco
	 */	
	public class Observer implements IObserver
	{
		/**
		 * 派发的任务
		 */		
		private var notifyFun:Function;
		
		/**
		 * 观察者的派发人
		 */		
		private var notifyCon:Object;
		
		public function Observer(notifyMethod:Function, notifyContext:Object)
		{
			super();
			setNotifyMethod(notifyMethod);
			setNotifyContext(notifyContext);
		}
		
		public function setNotifyMethod(method:Function):void
		{
			notifyFun = method;
		}
		
		public function setNotifyContext(context:Object):void
		{
			notifyCon = context;
		}
		
		/**
		 * 处理
		 *  
		 * @param notification : 通知
		 */		
		public function notify(notification:INotification):void
		{
			notifyFun.apply(notifyCon, [notification]);
		}
		
		public function compareNotifyContext(context:Object):Boolean
		{
			return notifyCon == context;
		}
		
	}
}